package com.shuogesha.platform.action.admin;

import static com.shuogesha.common.web.mongo.SimplePage.cpn;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shuogesha.common.util.JsonResult;
import com.shuogesha.common.util.ResultCode;
import com.shuogesha.common.web.mongo.Pagination; 
import com.shuogesha.platform.entity.Authentication;
import com.shuogesha.platform.service.AuthenticationService; 
 
@RestController 
@RequestMapping("/authentication/")
public class AuthenticationAct {
//	@RequestMapping(value = "/list")
//	public @ResponseBody Object v_list(String name, Integer pageNo, Integer pageSize, HttpServletRequest request,
//			HttpServletResponse response) throws UnsupportedEncodingException {
//		Pagination pagination = authenticationService.getPage(name, cpn(pageNo), pageSize);
//		return new JsonResult(ResultCode.SUCCESS, pagination);
//	}
//
//	@RequestMapping(value = "/get")
//	public @ResponseBody Object v_get(String id) {
//		Authentication bean = authenticationService.findById(id);
//		return new JsonResult(ResultCode.SUCCESS, bean);
//	}
//
//	@RequestMapping(value = "/save", method = RequestMethod.POST)
//	public @ResponseBody Object o_save(@RequestBody Authentication bean) {
//		authenticationService.save(bean);
//		return new JsonResult(ResultCode.SUCCESS, true);
//	}
//
//	@RequestMapping(value = "/update", method = RequestMethod.POST)
//	public @ResponseBody Object o_update(@RequestBody Authentication bean) {
//		authenticationService.update(bean);
//		return new JsonResult(ResultCode.SUCCESS, true);
//	}
//
//	@RequestMapping(value = "/delete")
//	public @ResponseBody Object o_delete(String[] ids) {
//		authenticationService.removeByIds(ids);
//		return new JsonResult(ResultCode.SUCCESS, true);
//	} 
//	 
	@Autowired
	public AuthenticationService authenticationService; 
	
	@RequestMapping(value = "/login")
	public JsonResult<Authentication> login(String username, String password, String ip,HttpServletRequest request, HttpServletResponse response) {
		return authenticationService.login(username, password, ip,request,response);
	}
	
	@RequestMapping(value = "/removeById")
	public JsonResult removeById(String id) {
		authenticationService.removeById(id);
		return new JsonResult(ResultCode.SUCCESS, true);
	} 
	
	@RequestMapping(value = "/findById")
	public Authentication findById(String id) { 
		return authenticationService.findById(id);
	} 
	
	@RequestMapping(value = "/retrieve")
 	public Authentication retrieve(String authId) {
		return authenticationService.retrieve(authId);
	}
}
